<? if(!defined('IN_TIPASK')) exit('Access Denied'); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"><? $user=$this->user; $setting=$this->setting; ?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tipask's Control Panel</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?=TIPASK_CHARSET?>">
<link media="all" type="text/css" href="css/common/admin/admincp.css" rel="stylesheet"/>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/common.js" type="text/javascript"></script>
</head>
<body>

<div id="append">
</div>
<div class="container"><? if(isset($message)) { $type=isset($type)?$type:'correctmsg';  ?><div class="<?=$type?>"><p><?=$message?></p></div><? } ?><h3>数据库备份</h3>
<div class="mainbox">
<form action="index.php?admin_db/backup" method="post" onsubmit="return docheck();">
<table class="datalist">
<tr>
<td colspan="4"><strong> 备份类型:</strong></td>
</tr>
<tr>
<td><input type="radio" name="type" value="full" class="radio" checked="checked" onclick="document.getElementById('showtables').style.display='none'">
全部备份(推荐)</td>
<td colspan="3"> 备份Tipask数据库所有表</td>
</tr>
<tr>
<td><input type="radio" name="type" value="stand" class="radio"  onclick="document.getElementById('showtables').style.display='none'">
 标准备份</td>
<td  colspan="3">备份常用的数据表,包括分类表、问题表、回答表、用户表、系统设置表</td>
</tr>
<tr>
<td><input type="radio" name="type" value="min" class="radio" onclick="document.getElementById('showtables').style.display='none'">
 最小备份</td>
<td  colspan="3"> 仅包括问题表、回答表</td>
</tr>
<tr>
<td><input type="radio" name="type" value="custom" class="radio" onclick="document.getElementById('showtables').style.display=''">
 自定义备份</td>
<td colspan="3"> 根据自行选择备份数据表</td>
</tr>

<tbody id="showtables" style="display:none">
<tr>
<td colspan="4"><input name="chkall" id="chkall" onClick="selectAll('tip','chkall','tables[]');" type="checkbox"><label id="tip"> 全选 </label></td>
</tr>
<tr>
<? if(is_array($tables)) { foreach($tables as $key => $value) { if($key%4!=0) { ?><td><input type="checkbox" value="<?=$value?>" name="tables[]"/><?=$value?></td><? } else { ?></tr>
<tr>
<td><input type="checkbox" value="<?=$value?>" name="tables[]"/><?=$value?></td><? } } } ?>
</tr>
</tbody>

<tr>
<td  colspan="4"><strong> 其他选项:</strong></td>
</tr>
<tr>
<td> 备份文件名</td>
<td colspan="3"><input type="text"  id="sqlfilename" name="sqlfilename" value="<?=$sqlfilename?>" size="25">.sql</td>
</tr>
<tr>
<td> 分卷文件大小</td>
<td colspan="3"><input type="text"  id="sizelimit" name="sizelimit" value="2048" size="15">KB</td>
</tr>
<tr>
<td> 压缩分卷文件</td>
<td colspan="3"><input type="radio" class="radio"  name="compression" value="1" > 多分卷压缩成一个文件</td>
</tr>
<tr>
<td></td>
<td colspan="3"><input type="radio" class="radio"  name="compression" value="0" checked> 不压缩</td>
</tr>
<tr>
<td colspan="4"><input name="backupsubmit" type="submit" class="btn" value="数据库备份" /></td>
</tr>
</table>
</form>
</div>

<h3> 数据库还原:</h3>
<table class="datalist" style="border-top:2px;">
<thead>
<tr>
<th style="width:320px;">SQL文件</td>
<th style="width:100px;">文件大小</td>
<th style="width:160px;">文件修改日期</td>
<th style="width:100px;">导入文件</td>
<th style="width:100px;">下载文件</td>
<th >删除文件</td>
</tr>
</thead>
<? if(is_array($filename)) { foreach($filename as $key => $value) { ?>
<tr>
<td><?=$value['filepath']?></td>
<td><?=$value['filesize']?></td>
<td><?=$value['filectime']?></td>
<td><a href="#" onclick="cofirmimport('<?=$value['filename']?>')" >导入文件</a></td>
<td><a href="#" onclick="download('<?=$value['filename']?>')">下载文件</a></td>
<td><a href="#" onclick="removefile('<?=$value['filename']?>')">删除文件</a></td>
</tr>
<? } } ?>
</table>
</div>
<script type="text/javascript" >
function cofirmimport(filename){
if(confirm('导入该sql文件会覆盖原来的数据!是否导入？')==false){
return false;
}else{
window.location='index.php?admin_db/import/'+filename.replace(/\./g,'*');
}
}
function removefile(filename){
if(confirm('删除数据库备份文件不可恢复!是否删除？')==false){
return false;
}else{
window.location='index.php?admin_db/remove/'+filename.replace(/\./g,'*');
}
}
function download(filename){
window.location='index.php?admin_db/downloadfile/'+filename.replace(/\./g,'*');
}
function selectAll(tipid,chkid,childname){
var chk=$("#"+chkid);
var infotip=$("#"+tipid);
if(chk.attr('checked')==true){
checkAll(childname,true);
}else{
checkAll(childname,false);
}
}
function checkAll(eleName,state){
$("input[name='"+eleName+"']").attr('checked',state);
}
function checkname(s){ 
var patrn=/^[a-zA-Z0-9]([a-zA-Z0-9]|[_])*$/;
return patrn.test(s) ;
}
function docheck(){
if($.trim($('#sqlfilename').val())==''|| !checkname($.trim($('#sqlfilename').val()))){
alert('文件名错误,请以字母或数字开头,并且名称中只允许有字母,数字和下划线');
return false;
}else if(isNaN($('#sizelimit').val())==true){
alert('分卷大小请填写数字');
return false;
}else if($('#sizelimit').val()<512){
alert('文件大小限制不要小于512K');
return false;
}else{
return true;
}
}
</script>
</body>
</html>
